<template>
  <div class="app-container">
    <el-form size="small" inline>
      <el-form-item :label="$t('Time')">
        <el-date-picker v-model="queryParams.date" type="date" value-format="yyyy-MM-dd" style="width: 240px" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryPage">
          {{ $t("Search") }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list">
      <el-table-column :label="$t('Code')" align="left" prop="code" min-width="120" />
      <el-table-column :label="$t('State')" align="left" prop="content" min-width="200" />
      <el-table-column :label="$t('Time')" align="right" prop="time" width="150" />
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="queryPage" />
  </div>
</template>

<script>
  import deviceLogAPI from "@/api/device/device-log";

  export default {
    name: "DeviceStateLog",
    data() {
      return {
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          date: null,
          code: null,
        },
        loading: false,
        list: [],
        total: 0,
      };
    },
    created() {
      this.queryPage()
    },
    methods: {
      queryPage() {
        const vm = this
        this.loading = true
        this.queryParams.code = this.$route.query.code
        deviceLogAPI.statePage(this.queryParams).then(res => {
          vm.list = res.rows
          vm.total = res.total
          vm.loading = false
        }).catch(() => {
          vm.loading = false
        })
      }
    }
  }

</script>
